package com.woniuxy.stage3demo.mapper.otherPzc;

import com.woniuxy.stage3demo.bean.otherPzc.AdsBean;
import com.woniuxy.stage3demo.bean.otherPzc.QainforBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface QainforMapper {
    /**
     * 新增帮助信息
     * @param qainforBean 新增的帮助信息对象
     * @return 数据库操作的行数
     */
    @Options(useGeneratedKeys = true,keyProperty = "q.id")
    @Insert("Insert into qainfor"+
            "(qa_no,qa_titel,qa_category,qa_text,status,create_time,del_flag)"+
            "values(#{q.qaNo},#{q.qaTitel},#{q.qaCategory},#{q.qaText},1,now(),0)")
    int saveQainfor(@Param("q") QainforBean qainforBean);
    /**
     * 删除帮助信息
     * @param id 删除的帮助信息对象的id
     * @return 数据库操作的行数
     */
    
    @Update("update qainfor set del_flag=1 where id=#{id}")
    int deleteQainfor(int id);

    /**
     * 修改帮助信息
     * @param qainforBean 修改的帮助信息对象
     * @return 操作行数
     */
    @Update("<script>" +
            "update qainfor" +
            "<set>" +
            "<if test='q.qaNo != null'>" +
            " qa_no = #{q.qaNo}," +
            "</if>" +
            "<if test='q.qaTitel != null'>" +
            " qa_titel = #{q.qaTitel}," +
            "</if>" +
            "<if test='q.qaCategory != null'>" +
            " qa_category = #{q.qaCategory}," +
            "</if>" +
            "<if test='q.qaText != null'>" +
            " qa_text = #{q.qaText}," +
            "</if>" +
            "<if test='q.status != null'>" +
            " status = #{q.status}," +
            "</if>" +
            "<if test='q.createTime != null'>" +
            " create_time = #{q.createTime}," +
            "</if>" +
            "</set>" +
            "where id = #{q.id}" +
            "</script>")
    int updateQainfor(@Param("q") QainforBean qainforBean);

    /**
     * 分页查询
     *
     * @param request
     * @param qainforBean
     * @return
     */
    List<QainforBean> findAllByParams(@Param("p") PageRequest request, @Param("q")QainforBean qainforBean);
}
